import QtQuick 2.12
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.5
//import Qt.labs.platform 1.1 as Plat
import QtQuick.Dialogs 1.3

Dialog {
    id: dialog_insert_words
   signal insertWords(string text, var font, string color);

    title: "插入文字"
    contentItem:     Item{
        anchors.fill: parent
        anchors.margins: 12

        Rectangle{
            width: parent.width
            height: 45
            color: "gray"
            RowLayout {
                anchors.verticalCenter:  parent.verticalCenter

                Label{
                    text: "文字:"
                }

                // 文字编辑框
                TextEdit {
                    id:current_words
                    width: 200

                    Layout.preferredWidth: 150
                    Layout.maximumWidth: 100
                    Layout.fillWidth: true
                }

                // 字体按钮
                Button {
                    text: "字体"
                    onClicked: {
                        font_dialog.visible = true
                    }
                }

                // 颜色按钮
                Button {
                    text: "颜色"
                    onClicked: {
                        color_dialog.visible = true
                    }
                }
            }
        }

        // 预览显示
        Text{
            id:preview
            text: current_words.text
            anchors.centerIn: parent
            font: font_dialog.font
            color: color_dialog.color
        }

        // 确认区
        RowLayout {
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter

            Button {
                text: "取消"
                onClicked: {
                    dialog_insert_words.close()
                }
            }

            Button {
                text: "确认"
                onClicked: {
                    // 发出信号
                    insertWords(preview.text, preview.font, preview.color)
                    dialog_insert_words.close()
                }
            }
        }
    }

    // 字体选择对话框
    FontDialog{
        id:font_dialog
    }

    // 颜色选择对话框
    ColorDialog{
        id:color_dialog
    }

}
